//
//  AppDelegate.m
//  财通年会
//
//  Created by 任玺 on 2017/1/16.
//  Copyright © 2017年 财通证券. All rights reserved.
//

#import "AppDelegate.h"
#import "CTWebViewController.h"

@interface AppDelegate () 

@end

@implementation AppDelegate
{
    BOOL _isFull;  //是否全屏
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    application.applicationSupportsShakeToEdit = NO;
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [self.window makeKeyAndVisible];
    
    NSURL *url = [NSURL URLWithString:@"http://minfo.ctsec.com/annualMeeting/mob/mob_index.html"];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url
                                                cachePolicy:NSURLRequestReloadIgnoringCacheData
                                            timeoutInterval:30];
    
    CTWebViewController *webVC = [[CTWebViewController alloc] initWithUrlRequest:urlRequest
                                                                           title:@"2017财通年会直播"
                                                                  isAlwaysRefesh:NO
                                                                        delegate:nil];
    
    UINavigationController *navigationCtr = [[UINavigationController alloc] initWithRootViewController:webVC];
    
    self.window.rootViewController = navigationCtr;
    
    [self setNavigationBarStyle];
    
    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


/**
 适配iOS 10 web播放器横屏时不自动全屏

 */
- (UIInterfaceOrientationMask)application:(UIApplication *)application
  supportedInterfaceOrientationsForWindow:( UIWindow *)window {
    
    if ([window isEqual:self.window]
        || [window isKindOfClass:NSClassFromString(@"UITextEffectsWindow")]) {
        return UIInterfaceOrientationMaskPortrait ;
    }

    return UIInterfaceOrientationMaskAllButUpsideDown;
}

#pragma mark - NavigationBarStyle
/**
 *  @brief  设置导航栏的样式
 */
-(void)setNavigationBarStyle {
    
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setShadowImage:[self imageWithColor:[UIColor clearColor]]];
    
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor], NSFontAttributeName:FONT_SYSTEM_RESIZED(18.0f)}];
    
    [[UINavigationBar appearance] setBarStyle:UIBarStyleDefault];
    [[UINavigationBar appearance] setBackgroundImage:[self imageWithColor:UIColorFromRGB(0x000000)] forBarMetrics:UIBarMetricsDefault];
    
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}

-(UIImage *)imageWithColor:(UIColor*)color
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

@end
